'=======================================
' 执行所有测试 case
'=======================================
Private Sub test_ALL_case()
    ' 初始化 + 取值测试
    test_init
    ' getDimensionLevelSize 测试
    test_error__getDimensionLevelSize_1
    test_error__getDimensionLevelSize_2

    ' InitBySizeArray 测试
    test_InitBySizeArray
    ' setdata getdata 测试
    test_get_set_data
    ' getPrimitiveData 测试
    test_getPrimitiveData
    ' getObjData 测试
    test_getObjData
End Sub

'=======================================
' 各方法的测试 case
'=======================================
' 初始化 + 取值测试
Private Sub test_init()
    Dim m As ArrayMatrix
    Set m = New ArrayMatrix
    m.Init 10
    
    Debug.Assert m.DimensionCount = 1
    Debug.Assert m.getDimensionLevelSize(0) = 10
    
    Set m = New ArrayMatrix
    m.Init 1, 2, 3, 4
    Debug.Assert m.DimensionCount = 4
    Debug.Assert m.getDimensionLevelSize(0) = 1
    Debug.Assert m.getDimensionLevelSize(1) = 2
    Debug.Assert m.getDimensionLevelSize(2) = 3
    Debug.Assert m.getDimensionLevelSize(3) = 4
    
    Set m = New ArrayMatrix
    Debug.Assert m.DimensionCount = 0

    Set m = New ArrayMatrix
    m.Init
    Debug.Assert m.DimensionCount = 0
    
    Dim arr(3) As Integer
    arr(0) = 1
    arr(1) = 2
    arr(2) = 3
    arr(3) = 4
    Set m = New ArrayMatrix
    m.InitBySizeArray arr
    Debug.Assert m.DimensionCount = 4
    Debug.Assert m.getDimensionLevelSize(0) = 1
    Debug.Assert m.getDimensionLevelSize(1) = 2
    Debug.Assert m.getDimensionLevelSize(2) = 3
    Debug.Assert m.getDimensionLevelSize(3) = 4
    
End Sub

' getDimensionLevelSize 测试
Private Sub test_error__getDimensionLevelSize_1()
On Error GoTo catch
    Dim m As ArrayMatrix
    Set m = New ArrayMatrix
    m.InitBySizeArray Array(6, 5, 4, 3)
    
    ' error !!!!!!!
    m.getDimensionLevelSize (-1)

    Debug.Assert False
catch:
    Debug.Assert Err.Number = 20020
End Sub

Private Sub test_error__getDimensionLevelSize_2()
On Error GoTo catch
    Dim m As ArrayMatrix
    Set m = New ArrayMatrix
    m.InitBySizeArray Array(6, 5, 4, 3)
    
    'error !!!!!!!
    m.getDimensionLevelSize (4)
    Debug.Assert False
catch:
    Debug.Assert Err.Number = 20021
End Sub

' InitBySizeArray 测试
Private Sub test_InitBySizeArray()
    Dim m As ArrayMatrix
    Set m = New ArrayMatrix
    m.InitBySizeArray Array(6, 5, 4, 3)
    
    m.setData "abc", 1, 2, 3, 2
    Dim str As String
    str = m.getData(1, 2, 3, 2)
    Debug.Assert str = "abc"
End Sub

' setdata getdata 测试
Private Sub test_get_set_data()
    Dim m As ArrayMatrix
    Set m = New ArrayMatrix
    m.Init 6, 5, 4, 3
    
    m.setData "abc", 1, 2, 3, 2
    Dim str As String
    str = m.getData(1, 2, 3, 2)
    Debug.Assert str = "abc"
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xyz"
    m.setData c, 4, 3, 2, 1
    Dim cx As Collection
    Set cx = m.getData(4, 3, 2, 1)
    Debug.Assert cx Is c

On Error GoTo catch:
    Set cx = m.getData(4, 3, 2, 2)
    GoTo continue:
catch:
    If Err.Number = 424 Then
        Set cx = Nothing
    Else
        Err.Raise Err.Number, Description:=Err.Description
    End If
continue:
    
    Debug.Assert cx Is Nothing
End Sub

' getPrimitiveData 测试
Private Sub test_getPrimitiveData()
    Dim m As ArrayMatrix
    Set m = New ArrayMatrix
    m.Init 6, 5, 4, 3, 3, 4
    
    Dim result1 As Variant
    result1 = m.getPrimitiveData(1, 2, 3, 2, 1, 3)
    Debug.Assert IsEmpty(result1)
    
    Dim result2 As String
    result2 = m.getPrimitiveData(1, 2, 3, 2, 1, 3)
    Debug.Assert result2 = ""
    
    m.setData "abc", 1, 2, 3, 2, 1, 3
    result1 = m.getPrimitiveData(1, 2, 3, 2, 1, 3)
    Debug.Assert result1 = "abc"
End Sub

' getObjData 测试
Private Sub test_getObjData()
    Dim m As ArrayMatrix
    Set m = New ArrayMatrix
    m.Init 6, 5, 4, 3, 3, 4
    
    Dim result1 As Object
    Set result1 = m.getObjData(1, 2, 3, 2, 1, 3)
    Debug.Assert result1 Is Nothing
    
    Dim c As Collection
    Set c = New Collection
    c.Add "xyz"
    m.setData c, 1, 2, 3, 2, 1, 3
    
    Dim cx As Collection
    Set cx = m.getObjData(1, 2, 3, 2, 1, 3)
    Debug.Assert cx Is c
End Sub
